import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { TSignConfig } from "../../../Message/Db/Tables/TSignConfig";
import { DateParser } from "../../common/tools/DateParser";
import { ClockManager } from "../manager/ClockManager";
//class HolidaySignConfig
    
    export  class HolidaySignConfig
    {
        constructor()
        {
            
            this._rewardArr = [];
            if (HolidaySignConfig._instance != null) 
            {
                throw new Error(" HolidaySignConfig 单例 ");
            }
            this.init();
            return;
        }

        public HolidaySignConfig.get rewardArr(): Array<any>
        {
            this._rewardArr.sortOn("id", Array.NUMERIC);
            return this._rewardArr;
        }

        public init(): void
        {
            var loc1=null;
            loc1 = ConfigManager.instance.getJSONByFileName("t_sign_config.json");
            this.write(loc1);
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TSignConfig();
                loc1.id = loc2.id;
                loc1.activeDt = DateParser.strToDateNormal(loc2.activeDt as string);
                loc1.itemCode = loc2.itemCode;
                loc1.dateDesc = loc2.dateDesc;
                this._rewardArr.push(loc1);
            }
            return;
        }

        public getChineseDate(): string
        {
            var loc3=null;
            var loc4=null;
            var loc1=ClockManager.instance.nowDate;
            var loc2=this._rewardArr.length;
            var loc5=0;
            while (loc5 < loc2) 
            {
                loc3 = (loc4 = this._rewardArr[loc5] as TSignConfig).activeDt;
                if (loc1.getFullYear() == loc3.getFullYear() && loc1.getMonth() == loc3.getMonth() && loc1.getDate() == loc3.getDate()) 
                {
                    return loc4.id.toString();
                }
                ++loc5;
            }
            return "1";
        }

        public getCelebrateString(): string
        {
            var loc4=null;
            var loc5=null;
            var loc1="";
            var loc2=ClockManager.instance.nowDate;
            var loc3=this._rewardArr.length;
            var loc6=0;
            while (loc6 < loc3) 
            {
                loc4 = (loc5 = this._rewardArr[loc6] as TSignConfig).activeDt;
                if (loc2.getFullYear() == loc4.getFullYear() && loc2.getMonth() == loc4.getMonth() && loc2.getDate() == loc4.getDate()) 
                {
                    return "holidaySignChu" + (loc6 + 1);
                }
                ++loc6;
            }
            return "holidaySignChu10";
        }

        public static get instance(): HolidaySignConfig
        {
            if (!HolidaySignConfig._instance) 
            {
                HolidaySignConfig._instance = new HolidaySignConfig();
            }
            return HolidaySignConfig._instance;
        }

        /* internal */ /* var */_rewardArr: Array<any>;

        /* internal */ static /* var */_instance: HolidaySignConfig;
    }
